<?php
/**
 * 2017年6月6日13:31:09
 * PDO SAFE
 */
include 'common.php';
$username = $_COOKIE['username'];
$token = $_COOKIE['token'];
$hope = $_REQUEST['hope_msg'];
$hopetype = $_REQUEST['hope_type'];
$uuid = $_REQUEST['uuid'];

try {	
	$dbc = pdo_root_connect();
	
	$stmt = $dbc->prepare('select * from userinfo where username=:username and token=:token');
	$stmt->bindParam(':username', $username);
	$stmt->bindParam(':token', $token);
	$stmt->execute();
	if($stmt->rowCount() > 0){
		
		if((strlen($hope) > 6) && (strlen($hope) < 1024)){
		
			$stmt2 = $dbc->prepare('insert into userwish (username, hopetype, uploadtime, msg, uuid) values (:username, :hopetype, unix_timestamp(now()), :hope, :uuid)');
			
			$stmt2->bindParam(':username', $username);
			$stmt2->bindParam(':hopetype', $hopetype, PDO::PARAM_INT);
			$stmt2->bindParam(':hope', $hope, PDO::PARAM_STR);
			$stmt2->bindParam(':uuid', $uuid, PDO::PARAM_STR, 8);
			$stmt2->execute();
			if($stmt2->rowCount() > 0){
				$errorcode = 1;//添加记录成功
			}else{
				$errorcode = 7;//添加记录失败
				echo json_encode($stmt2->errorInfo());
			}
		}else{
			$errorcode = 6;//长度不符合要求
		}
	}else
	{
		$errorcode = 3;
	}
}catch (PDOException $e){
	$msg = $e->getMessage();
	$errorcode = 4;
}
echo json_encode(array('errorcode'=>$errorcode, 'msg' => $msg));

?>